var e = require, t = module, n = exports;

Object.defineProperty(n, "__esModule", {
    value: !0
}), n.NativeAdItem = void 0;

var o = e("GameConfig");

n.NativeAdItem = function() {};

var i = function() {
    function t() {
        this.moveUp = 0, this.currBannerAd = null, this.currBannerAdIsShow = 0, this.currBannerAdCanShow = 0, 
        this.currInterstitialAd = null, this.currInterstitialAdStatus = 0, this.currInterstitialAdStartTime = 0, 
        this.currAppBoxAd = null, this.currAppBoxAdStatus = 0, this.nativeAd = null, this.nativeAdList = [], 
        this.nativeAdItem = null, this.nativeFlag = 0, this.nativeCount = 0, this.nativeAdSuccess = null, 
        this.nativeAdFail = null;
    }
    return t.getInstance = function() {
        return this._instance || (this._instance = new t()), this._instance;
    }, t.prototype.init = function() {
        try {
            var i;
            0 < o.GC.bannerAdUnitIds.length && (i = [], o.GC.bannerAdUnitIds.forEach(function(t) {
                return i.push({
                    adId: t
                });
            }), this.initBannerAd({
                list: i
            })), o.GC.videoAdUnitId && this.initRewardVideoAd({
                adid: o.GC.videoAdUnitId
            }), o.GC.interstitialAdUnitId && this.initInterstitialAd({
                adid: o.GC.interstitialAdUnitId
            }), o.GC.appBoxAdUnitId && this.initAppBoxAd({
                adid: o.GC.appBoxAdUnitId
            });
        } catch (t) {
            console.error(t);
        }
    }, t.prototype.initBannerAd = function(t) {
        GA.initBannerAd(t.list);
    }, t.prototype.showBannerAd = function(i) {
        var o = this;
        if (!this.currBannerAdIsShow) {
            this.currBannerAdIsShow = 1;
            try {
                GA.showBanner({
                    style: {
                        width: i.width || 0,
                        height: i.height || 180,
                        offsetY: i.moveUp
                    },
                    fail: function() {
                        var t;
                        o.currBannerAdIsShow = 0, null === (t = null == i ? void 0 : i.fail) || void 0 === t || t.call(i);
                    }
                });
            } catch (t) {}
        }
    }, t.prototype.showBanner = function() {
        GA.isPlatform([ GA.Platform.iOS, GA.Platform.Android ]) || (GA.isPlatform(GA.Platform.QQ) ? t.getInstance().showBannerAd({
            width: 300,
            height: 150,
            moveUp: 0
        }) : t.getInstance().showBannerAd({
            height: 180
        }));
    }, t.prototype.hideBannerAd = function(t) {
        if (this.currBannerAdIsShow) {
            this.currBannerAdIsShow = 0;
            try {
                t.tag ? GA.hideBanner(t.tag) : GA.hideBanner();
            } catch (t) {}
        }
    }, t.prototype.hideBanner = function(t) {
        GA.isPlatform([ GA.Platform.iOS, GA.Platform.Android ]) || this.hideBannerAd(t);
    }, t.prototype.hideAllBanner = function() {
        GA.isPlatform([ GA.Platform.iOS, GA.Platform.Android ]) || this.hideBannerAd({});
    }, t.prototype.initRewardVideoAd = function(t) {
        t.adid && GA.initRewardVideoAd([ t.adid ]);
    }, t.prototype.initInterstitialAd = function(t) {
        var i = this;
        if (GA.isPlatform([ GA.Platform.iOS, GA.Platform.Android ])) console.log("interstitialAd init"); else try {
            this.currInterstitialAd = GA.PA.createInterstitialAd({
                adUnitId: t.adid
            }), this.currInterstitialAd && (console.log("interstitialAd init success"), this.loadInterstitialAd(), 
            this.currInterstitialAd.onLoad(function() {
                console.log("interstitialAd onLoad success");
            }), this.currInterstitialAd.onError(function(t) {
                console.log("interstitialAd onError with:" + t.errCode + "," + t.errMsg);
            }), this.currInterstitialAd.onClose(function() {
                console.log("interstitialAd onClose success"), i.currInterstitialAdStatus = 0, i.loadInterstitialAd();
            }));
        } catch (t) {}
    }, t.prototype.loadInterstitialAd = function(t, i) {
        var o = this;
        this.currInterstitialAd && 0 == this.currInterstitialAdStatus && (this.currInterstitialAdStatus = 1, 
        this.currInterstitialAd.load().then(function() {
            o.currInterstitialAdStatus = 2, console.log("interstitialAd load success"), t && t();
        }).catch(function(t) {
            o.currInterstitialAdStatus = 0, console.log("interstitialAd load fail with:" + t.errCode + "," + t.errMsg), 
            i && i();
        }));
    }, t.prototype.showInterstitialAd = function(t) {
        var i = this;
        if (GA.isPlatform([ GA.Platform.iOS, GA.Platform.Android ])) {
            console.log("interstitialAd show");
            try {
                GA.showInterstitialAd();
            } catch (t) {}
        } else if (0 == this.currInterstitialAdStatus) this.loadInterstitialAd(function() {
            i.showInterstitialAd(t);
        }, function() {
            try {
                GA.PA.showToast({
                    title: "加载失败",
                    icon: "none"
                });
            } catch (t) {}
        }); else if (1 == this.currInterstitialAdStatus) try {
            GA.PA.showToast({
                title: "加载中...",
                icon: "none"
            });
        } catch (t) {} else 2 == this.currInterstitialAdStatus && this.currInterstitialAd.show().then(function() {
            console.log("interstitialAd show success");
        }).catch(function(t) {
            console.log("interstitialAd show fail with:" + t.errCode + "," + t.errMsg);
        });
    }, t.prototype.initAppBoxAd = function(t) {
        var i = this;
        if (t.adid) try {
            GA.isPlatform(GA.Platform.QQ) ? this.currAppBoxAd = GA.PA.createAppBox({
                adUnitId: t.adid
            }) : GA.isPlatform(GA.Platform.OPPO) ? this.currAppBoxAd = GA.PA.createGamePortalAd({
                adUnitId: t.adid
            }) : GA.isPlatform(GA.Platform.Vivo) && (this.currAppBoxAd = GA.PA.createBoxPortalAd({
                posId: t.adid,
                marginTop: 320 / GA.PA.getSystemInfoSync().designPixelRatio
            })), this.currAppBoxAd && (console.log("appBoxAd init success"), this.loadAppBoxAd(), 
            this.currAppBoxAd.onLoad(function() {
                console.log("appBoxAd onLoad success");
            }), this.currAppBoxAd.onError(function(t) {
                console.log("appBoxAd onError with:" + t.errCode + "," + t.errMsg);
            }), this.currAppBoxAd.onClose(function() {
                console.log("appBoxAd onClose success"), i.currAppBoxAdStatus = 0, i.loadAppBoxAd();
            }));
        } catch (t) {}
    }, t.prototype.loadAppBoxAd = function(t, i) {
        var o = this;
        GA.isPlatform(GA.Platform.Vivo) ? (this.currAppBoxAdStatus = 2, console.log("appBoxAd load success"), 
        t && t()) : 0 == this.currAppBoxAdStatus && (this.currAppBoxAdStatus = 1, this.currAppBoxAd.load().then(function() {
            o.currAppBoxAdStatus = 2, console.log("appBoxAd load success"), t && t();
        }).catch(function(t) {
            o.currAppBoxAdStatus = 0, console.log("appBoxAd load fail with:" + t.errCode + "," + t.errMsg), 
            i && i();
        }));
    }, t.prototype.showAppBoxAd = function() {
        var t = this;
        if (GA.isPlatform([ GA.Platform.OPPO, GA.Platform.QQ, GA.Platform.Vivo ]) && this.currAppBoxAd) if (0 == this.currAppBoxAdStatus) this.loadAppBoxAd(function() {
            t.showAppBoxAd();
        }, function() {
            try {
                GA.PA.showToast({
                    title: "加载失败",
                    icon: "none"
                });
            } catch (t) {}
        }); else if (1 == this.currAppBoxAdStatus) try {
            GA.PA.showToast({
                title: "加载中...",
                icon: "none"
            });
        } catch (t) {} else 2 == this.currAppBoxAdStatus && this.currAppBoxAd.show().then(function() {
            console.log("appBoxAd show success");
        }).catch(function(t) {
            console.log("appBoxAd show fail with:" + t.errCode + "," + t.errMsg);
        });
    }, t.prototype.initNativeAd = function(t) {
        var i = this;
        GA.Info.isPreview ? GA.log("Preview 不支持 initNativeAd") : GA.isPlatform([ GA.Platform.OPPO, GA.Platform.Vivo ]) && (this.nativeAd = GA.PA.createNativeAd({
            adUnitId: t
        }), this.nativeAd.onLoad(function(t) {
            console.log("nativeAd onLoad", t);
            try {
                i.nativeAdSuccess(t);
            } catch (t) {}
        }), this.nativeAd.onError(function(t) {
            console.log("nativeAd onError", t);
            try {
                i.nativeAdFail(t);
            } catch (t) {}
        }));
    }, t.prototype.loadNativeAd = function(t, i, o) {
        var r = this;
        if (void 0 === t && (t = ""), GA.isPlatform([ GA.Platform.OPPO, GA.Platform.Vivo ])) this.nativeAd && (this.nativeAdSuccess = function(t) {
            try {
                i(t);
            } catch (t) {}
        }, this.nativeAdFail = function(t) {
            try {
                o(t);
            } catch (t) {}
        }, this.nativeAd.load()); else if (GA.isPlatform(GA.Platform.Android)) {
            console.log("nativeAd oppo load");
            try {
                GA.PA.loadOppoNativeAd(function(t) {
                    if (t.imageUrl) {
                        0 < r.nativeAdList.length && r.nativeAdList.forEach(function(t) {
                            try {
                                GA.PA.destroyOppoNativeAd(t.adId);
                            } catch (t) {}
                        });
                        try {
                            i({
                                adList: [ {
                                    adId: t.id,
                                    imgUrlList: [ t.imageUrl ]
                                } ]
                            });
                        } catch (t) {}
                    } else try {
                        o(), GA.PA.destroyOppoNativeAd(t.id);
                    } catch (t) {}
                });
            } catch (t) {}
        }
    }, t.prototype.reportAdShow = function(t) {
        if (GA.isPlatform([ GA.Platform.OPPO, GA.Platform.Vivo ])) this.nativeAd && this.nativeAd.reportAdShow({
            adId: t
        }); else if (GA.isPlatform(GA.Platform.Android)) try {
            GA.PA.reportOppoNativeAdShow(t);
        } catch (t) {
            GA.error(t);
        }
    }, t.prototype.reportAdClick = function(t) {
        if (GA.isPlatform([ GA.Platform.OPPO, GA.Platform.Vivo ])) this.nativeAd && this.nativeAd.reportAdClick({
            adId: t
        }); else if (GA.isPlatform(GA.Platform.Android)) try {
            GA.PA.reportOppoNativeAdClick(t);
        } catch (t) {
            GA.error(t);
        }
    }, t._instance = null, t;
}();

n.default = i;